package com.tianshi.order.mapper;


import com.tianshi.entity.Carts;
import org.apache.ibatis.annotations.*;

@Mapper
public interface CartMapper {


//    @Options(useGeneratedKeys = true, keyProperty = "cartId", keyColumn = "cart_id")
    @Select("SELECT * FROM carts WHERE user_id = #{userId}")
    Carts getCartByUserId(Long userId);


    //将购物车的id存到cartId中
    @Options(useGeneratedKeys = true, keyProperty = "cartId", keyColumn = "cart_id")
    @Insert("insert into carts(cart_id,user_id,created_at,updated_at) values(#{cartId},#{userId},#{createdAt},#{updatedAt})")
    Integer insert(Carts cart);

    void update(Carts cart);

    @Select("SELECT * FROM carts WHERE cart_id = #{cartId}")
    Carts getCartByCartId(Long cartId);


    @Delete("DELETE FROM carts WHERE cart_id = #{cartId}")
    void delete(Long cartId);
}
